package com.endoc.designpattern.compose;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 区域节点
 *此处父类让子类去实现对节点的删除和增加
 */
public class DistrictNode extends Node{

    List<Node> mChildrenList =new ArrayList<>();

    public DistrictNode(String name) {
      this.name =name;
    }

    @Override
    public List<Node> getChildren() {
        return mChildrenList;
    }

    public void removeNode(Node node){
        mChildrenList.remove(node);
    }

    public void addNode(Node node){
        mChildrenList.add(node);
    }

    @NonNull
    @Override
    public String toString() {
        StringBuffer stringBuffer = new StringBuffer(name);
        for (Node node:mChildrenList) {
            stringBuffer.append("\n").append(node.toString());
        }
        return stringBuffer.toString();
    }
}
